package com.wpml.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wpml.common.util.PageUtils;
import com.wpml.common.util.Query;
import com.wpml.product.entity.AttrAttrgroupRelationModel;
import com.wpml.product.dao.AttrAttrgroupRelationDao;
import com.wpml.product.service.AttrAttrgroupRelationService;
import com.wpml.product.vo.AttrGroupRelationVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 属性&属性分组关联(PmsAttrAttrgroupRelation)表服务实现类
 *
 * @author makejava
 * @since 2020-04-07 11:33:36
 */
@Service
@Slf4j
public class AttrAttrgroupRelationServiceImpl extends ServiceImpl<AttrAttrgroupRelationDao, AttrAttrgroupRelationModel> implements AttrAttrgroupRelationService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<AttrAttrgroupRelationModel> page = this.page(
                new Query<AttrAttrgroupRelationModel>().getPage(params),
                new QueryWrapper<AttrAttrgroupRelationModel>()
        );

        return new PageUtils(page);
    }

    @Override
    public void saveBatch(List<AttrGroupRelationVo> vos) {
        List<AttrAttrgroupRelationModel> collect = vos.stream().map(item -> {
            AttrAttrgroupRelationModel relationEntity = new AttrAttrgroupRelationModel();
            BeanUtils.copyProperties(item, relationEntity);
            return relationEntity;
        }).collect(Collectors.toList());
        this.saveBatch(collect);
    }
}
